library(tidyverse)
library(DeclareDesign)
library(rdss)

sims <- 2000
bootstrap_sims <- 2000

source("code/declarations/declaration_19.1.R")

most_common <- 
  function(x) {
    ux <- unique(x)
    ux[which.max(tabulate(match(x, ux)))]
  }

discovery_diagnosands  <- 
  declare_diagnosands(
    correct = mean(estimate == estimand),
    bias = mean(estimate - estimand),
    rmse = sqrt(mean((estimate - estimand)^2)),
    mean_estimate = mean(estimate),
    modal_estimate = most_common(round(estimate, 1)),
    mean_estimand = mean(estimand),
    modal_estimand = most_common(round(estimand, 1))
  )

diagnosis_19.1 <- diagnose_design(declaration_19.1, diagnosands = discovery_diagnosands, sims = sims, bootstrap_sims = bootstrap_sims) 

write_rds(diagnosis_19.1, file = "diagnosis_objects/diagnosis_19.1.rds")
